package com.atguigu.dga.common.utils;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

// 获取Spring容器中的bean，根据组件上标识的名称获取
@Component
public class SpringBeanProvider implements ApplicationContextAware {

    private   ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext=applicationContext;
    }


    public <T>  T getBean(String beanName, Class<T> clazz){  // 根据bean名称获取bean 同时也给一个该组件的对象类型
       return   applicationContext.getBean(beanName, clazz);
    }
}
